@extends('home.layout');
@section('css')
    .white-pink {
    margin-left:auto;
    margin-right:auto;

    max-width: 500px;
    background: #FFF;
    padding: 30px 30px 20px 30px;
    box-shadow: rgba(187, 187, 187, 1) 0 0px 20px -1px;
    -webkit-box-shadow: rgba(187, 187, 187, 1) 0 0px 20px -1px;
    font: 12px Arial, Helvetica, sans-serif;
    color: #666;
    border-radius: 10px;
    -webkit-border-radius: 10px;
    }
    .white-pink h1 {
    font: 24px "Trebuchet MS", Arial, Helvetica, sans-serif;
    padding: 0px 0px 10px 40px;
    display: block;
    border-bottom: 1px solid #F5F5F5;
    margin: -10px -30px 10px -30px;
    color: #969696;
    }
    .white-pink h1>span {
    display: block;
    font-size: 11px;
    color: #C4C2C2;
    }
    .white-pink label {
    display: block;
    margin: 0px 0px 5px;
    }
    .white-pink label>span {
    float: left;
    width: 20%;
    text-align: right;
    padding-right: 10px;
    margin-top: 10px;
    color: #969696;
    }
    .white-pink input[type="text"], .white-pink input[type="email"], .white-pink textarea,.white-pink select{
    color: #555;
    width: 70%;
    padding: 3px 0px 3px 5px;
    margin-top: 2px;
    margin-right: 6px;
    margin-bottom: 16px;
    border: 1px solid #e5e5e5;
    background: #fbfbfb;
    height: 25px;
    line-height:15px;
    outline: 0;
    -webkit-box-shadow: inset 1px 1px 2px rgba(200,200,200,0.2);
    box-shadow: inset 1px 1px 2px rgba(200,200,200,0.2);
    }
    .white-pink textarea{
    height:100px;
    padding: 5px 0px 0px 5px;
    width: 70%;
    }
    .white-pink .button {
    -moz-box-shadow:inset 0px 1px 0px 0px #fbafe3;
    -webkit-box-shadow:inset 0px 1px 0px 0px #fbafe3;
    box-shadow:inset 0px 1px 0px 0px #fbafe3;
    background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #ff5bb0), color-stop(1, #ef027d) );
    background:-moz-linear-gradient( center top, #ff5bb0 5%, #ef027d 100% );
    filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff5bb0', endColorstr='#ef027d');
    background-color:#ff5bb0;
    border-radius:9px;
    -webkit-border-radius:9px;
    -moz-border-border-radius:9px;
    border:1px solid #ee1eb5;
    display:inline-block;
    color:#ffffff;
    font-family:Arial;
    font-size:15px;
    font-weight:bold;
    font-style:normal;
    height: 40px;
    line-height: 30px;
    width:100px;
    text-decoration:none;
    text-align:center;
    text-shadow:1px 1px 0px #c70067;
    }
    .white-pink .button:hover {
    background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #ef027d), color-stop(1, #ff5bb0) );
    background:-moz-linear-gradient( center top, #ef027d 5%, #ff5bb0 100% );
    filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ef027d', endColorstr='#ff5bb0');
    background-color:#ef027d;
    }
    .white-pink .button:active {
    position:relative;
    top:1px;
    }
    .white-pink select {
    background: url('down-arrow.png') no-repeat right, -moz-linear-gradient(top, #FBFBFB 0%, #E9E9E9 100%);
    background: url('down-arrow.png') no-repeat right, -webkit-gradient(linear, left top, left bottom, color-stop(0%,#FBFBFB), color-stop(100%,#E9E9E9));
    appearance:none;
    -webkit-appearance:none;
    -moz-appearance: none;
    text-indent: 0.01px;
    text-overflow: '';
    width: 70%;
    line-height: 15px;
    height: 30px;
    }   
@endsection
@section('content')
	
    <div class="white-pink" style="margin-top:40px; margin-top: 40px;">
        <form action="/home/goods/insert" method="post" class="STYLE-NAME" enctype="multipart/form-data">
            {{csrf_field()}}
            <h1>卖家发布商品
            <span>填写卖家发布商品信息</span>
            </h1>
            @if(session('error'))
                    {{session('error')}}
            @endif
            @if (count($errors) > 0)
                @foreach ($errors->all() as $error)
                    <h3 style="color:#f69;">{{ $error }}</h3>
                @endforeach
         
            @endif
            <label>
            <span>商品名称 :</span>
            <input id="name" type="text" name="goodsname" placeholder="请填写商品名称" value="{{old('goodsname')}}"/>
            </label>
            <label>
            <span>商品价格 :</span>
            <input id="name" type="text" name="value" placeholder="请填写商品价格" value="{{old('value')}}" />
            </label>
            <label>
            <span>所属店铺 :</span>
            <input id="name" type="text" name="isshop" placeholder="请填写商品所属店铺" value="{{old('isshop')}}" />
            </label>
            <label>
            <span>商品库存 :</span>
            <input id="name" type="text" name="inventory" placeholder="请填写商品库存" value="{{old('inventory')}}"/>
            </label>
    
            <label>
            <span>商品描述 :</span>
            <textarea id="message" required name="description" placeholder="请填写商品描述" value="{{old('description')}}" style="resize:none"></textarea>
            </label>
            <label>
            <span>商品状态 :</span><select  required name="status">
                    <option value="1">在售</option>
                    <option value="0">下架</option>
            </select>
            </label>
            <label>
            <span>商品logo :</span>
            <input id="name" type="file" name="logo" placeholder="请填写商品logo" />
            </label>
            <label>
            <span>商品种类 :</span><select required name="cid" onchange = "return get_shop()" >
                    <option selected disabled>请选择</option>
                    @foreach($data as $v)
                        <option value="{{$v->id}}" >{{$v -> name}}</option>
                    @endforeach   
            </select>
            </label>
            <label class="abc1">

            </label>
            <label class="abc">

            </label>
            <!-- <div class="abc1"> -->
            <!-- <div class="abc"> -->
            <label>
            <span>&nbsp;</span>
            <input type="submit" class="button" value="提交信息" />&nbsp;&nbsp;&nbsp;<input type="reset" class="button" value="重置信息" />
            </label>
        </form>
    </div>
    <script type="text/javascript">
                 function function1(attrname)
                {
           
                    $.ajaxSetup({
                    headers: {
                      'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    }
                   });
                    $.ajax({
                        type:'POST',
                        url:'/home/goods/check2',
                        data:'attrname='+attrname,
                        success:function(data)
                        {
                            
                            var count = data.length;
                            var i = 0;
                            var b ='';
                            b+="<span>"+attrname+" :</span><select name="+attrname+">";
                            for(i=0;i<count;i++){
                                // alert(data[i].name);
                                b+="<option>"+data[i].name+"</option>";
                            }
                            b+="</select></div>";


                            $('.abc').append(b);

                        },
                        dataType:'json'
                    });
                }

                function get_shop()
                {
                    $('.abc').html('');
                    $.ajaxSetup({
                    headers: {
                      'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    }
                   });

                    var id = $("select[name='cid']").val();

                    $.ajax({
                        type:'POST',
                        url:'/home/goods/check3',
                        data:'id='+id,
                        success:function(data)
                        {   

                            var count = data.length;
                            var i = 0;
                            var b ="<span>类目 :</span><select name=type>";
                            for(i=0;i<count;i++){
                                b+= "<option value="+data[i].id+">"+data[i].name+"</option>"
                            }
                            b+="</select>";
                            $('.abc1').html(b);
                        },
                        dataType:'json'
                    });  

                    $.ajax({
                        type:'POST',
                        url:'/home/goods/check',
                        data:'id='+id,
                        success:function(data)
                        {
           
                            var count = data.length;
                            var i = 0;
                        
                            for(i=0;i<count;i++){

                                function1(data[i].name);
                            }
                      
                        },
                        dataType:'json'
                    });

                }

            </script>


@endsection